package com.yunfeisoft.base.model;

import com.yunfeisoft.common.base.BaseModel;
import com.yunfeisoft.common.sql.record.TransientField;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * ClassName: WorkflowInstance
 * Description: 流程实例
 *
 * @Author: Jackie liu
 * Date: 2020-01-03
 */
@Entity
@Table(name = "TS_WORKFLOW_INSTANCE")
public class WorkflowInstance extends BaseModel implements Serializable {

    /**
     * Field serialVersionUID: 序列号
     */
    private static final long serialVersionUID = 1L;

    /**
     * 流程定义id
     */
    @Column
    private String workflowDefineId;

    /**
     * 表单id
     */
    @Column
    private String formId;

    /**
     * 标题
     */
    @Column
    private String title;

    /**
     * 状态
     */
    @Column
    private Integer status;

    @TransientField
    private String defineFormPath;

    public String getStatusStr() {
        return WorkflowInstanceStatusEnum.valueOf(status);
    }

    public String getWorkflowDefineId() {
        return workflowDefineId;
    }

    public void setWorkflowDefineId(String workflowDefineId) {
        this.workflowDefineId = workflowDefineId;
    }

    public String getFormId() {
        return formId;
    }

    public void setFormId(String formId) {
        this.formId = formId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getDefineFormPath() {
        return defineFormPath;
    }

    public void setDefineFormPath(String defineFormPath) {
        this.defineFormPath = defineFormPath;
    }

    public enum WorkflowInstanceStatusEnum {

        APPROVALING(1, "审批中"),
        ACCEPT(2, "已通过"),
        REJECT(3, "已驳回");

        private int value;
        private String label;

        private WorkflowInstanceStatusEnum(int value, String label) {
            this.value = value;
            this.label = label;
        }

        public static String valueOf(Integer value) {
            if (value == null) {
                return null;
            }
            for (WorkflowInstanceStatusEnum loop : WorkflowInstanceStatusEnum.values()) {
                if (value == loop.getValue()) {
                    return loop.getLabel();
                }
            }
            return null;
        }

        public int getValue() {
            return value;
        }

        public String getLabel() {
            return label;
        }
    }
}